import { pipeline, env } from "@xenova/transformers"

env.allowLocalModels = false
env.allowRemoteModels = true
// `/learn-english/wasm/` 为Gitee pages环境下的路径
env.backends.onnx.wasm.wasmPaths = import.meta.env.DEV ? `/wasm/` : `/learn-english/wasm/`

async function start() {
    try {
        const pipe = await pipeline(
            "automatic-speech-recognition",
            "Xenova/whisper-tiny.en"
        )
        addEventListener("message", async (e) => {
            const r = await pipe(e.data)
            postMessage(r)
        })
        postMessage("ready")
    } catch (e) {
        postMessage(e)
    }
}

start()
